#ifndef __SINGLELIST__
#define __SINGLELIST__
#include <iostream>
class Node{
public:
	Node():next(NULL){}
	Node(int num):data(num),next(NULL){}
	int data;
	Node * next;
};

Node* CreateList(){
	Node *head,*p,*n;
	head = new Node();
	p = head;
	for(;;){
		std::cout<<"input num:"<<std::endl;
		int temp ;
		std::cin>>temp;
		if(temp == 0) break;
		n = new Node(temp);
		p->next = n;
		p = p->next;
	}
	head = head->next;
	//if(head != NULL)
	//	std::cout<<"head is "<< head->data <<std::endl;
	return head;
}

void ShowList(Node* head){
	Node *p = head;
	for(;;){
		if(p == NULL) break;
		std::cout<< p->data<<" ";
		p = p->next;
	}
	std::cout<<std::endl;
}

int GetLength(Node* head){
	Node *p = head;
	int cnt = 0;
	for(;;){
		if(p == NULL) break;
		++cnt;
		p=p->next;
	}
	return cnt;
}

void Delete(Node **head, int num){
	if(*head == NULL) return;
	if((*head)->data == num){
		Node *h = *head;
		*head = (*head)->next;
		delete h;
		return;
	}
	Node *p = *head;
	for(;;){
		if(p->next == NULL || p->next->data == num) break;
		p = p->next;
	}
	if(p->next == NULL) return;
	Node *d = p->next;
	p->next = p->next->next;
	delete d;
}

void Insert(Node **head, int index, int num){
	if(*head == NULL) {
		*head = new Node(num);
		return;
	}
	Node *p;
	if(index <= 0){
		p = new Node(num);
		p->next = *head;
		*head = p;
		return;
	}
	int cnt = 0;
	p = *head;
	for(;;){
		if(++cnt == index || p->next == NULL) break;
		p = p->next;
	}
	Node * t =new Node(num);
	t->next = p->next;
	p->next = t;
}

void Sort(Node **head){
	if(*head == NULL || (*head)->next == NULL) return;
	Node *p;
	int len = GetLength(*head);
	for(int i = 0; i < len-1; ++i){
		p = *head;
		for(;;){
			if(p->next == NULL) break;
			if(p->data > p->next->data){
				int temp = p->data;
				p->data = p->next->data;
				p->next->data = temp;
			}
			p = p->next;
		}
	}
}

void Reverse(Node **head){
	if(*head == NULL || (*head)->next == NULL) return;
	Node *p1,*p2,*p3;
	p1= *head; p2 = p1->next;
	for(;;){
		if(p2 == NULL) break;
		p3 = p2->next;
		p2->next = p1;
		p1 = p2;
		p2 = p3;
	}
	(*head)->next = NULL;
	*head = p1;
}
#endif